package com.malty.mall.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.malty.mall.dao.pms.PmsProductAttributeCategoryMapper;
import com.malty.mall.domain.dto.req.pms.PmsAttributeCategoryParam;
import com.malty.mall.domain.entity.pms.PmsProductAttributeCategory;
import com.malty.mall.service.pms.IPmsProductAttributeCategoryService;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author malty
 */
@Service
public class PmsProductAttributeCategoryServiceImpl extends ServiceImpl<PmsProductAttributeCategoryMapper, PmsProductAttributeCategory> implements IPmsProductAttributeCategoryService {
    @Override
    public Boolean create(PmsAttributeCategoryParam cateParam) {
        PmsProductAttributeCategory category = new PmsProductAttributeCategory(cateParam);
        return this.save(category);
    }

    @Override
    public Boolean updateCategoryById(PmsAttributeCategoryParam cateParam) {
        PmsProductAttributeCategory category = new PmsProductAttributeCategory(cateParam);
        return this.updateById(category);
    }

    @Override
    public PmsAttributeCategoryParam queryCateById(Integer id) {
        PmsProductAttributeCategory category = this.getById(id);
        return new PmsAttributeCategoryParam(category);
    }

    @Override
    public Boolean deleteById(Long id) {
        return this.removeById(id);
    }

    @Override
    public List<PmsAttributeCategoryParam> list(Integer pageNum, Integer pageSize) {
        Page<PmsProductAttributeCategory> page = new Page<>(pageNum, pageSize);
        Page<PmsProductAttributeCategory> categoryPage = this.page(page);
        List<PmsProductAttributeCategory> records = categoryPage.getRecords();
        return PmsAttributeCategoryParam.attributeCateParams(records);
    }

    @Override
    public List<PmsAttributeCategoryParam> listWithAttr() {
        return null;
    }
}
